package com.lzz.bottomencapsulation.customview.selectimage;


import com.lzz.bottomencapsulation.customview.selectimage.utils.FileUtils;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * 选择器配置参数
 */
public class ImageConfig {

    private boolean mutiSelect;//是否单选

    private int maxSize;//选择图片的最大数量

    private boolean showCamera;//是否显示相机选择

    private boolean crop;//是否剪裁
    /**
     * 图片剪裁尺寸
     */
    private int aspectX;
    private int aspectY;
    private int outputX;
    private int outputY;

    private ImageLoader imageLoader;//图片显示器

    private String filePath;//图片存储路径

    private ArrayList<String> pathList;//默认选择的图片路径

    private int requestCode;//图片选择后制定返回用于判断的标识


    private ImageConfig(final Builder builder) {
        this.maxSize = builder.maxSize;
        this.showCamera = builder.showCamera;
        this.imageLoader = builder.imageLoader;
        this.mutiSelect = builder.mutiSelect;
        this.pathList = builder.pathList;
        this.filePath = builder.filePath;
        this.crop = builder.crop;
        this.aspectX = builder.aspectX;
        this.aspectY = builder.aspectY;
        this.outputX = builder.outputX;
        this.outputY = builder.outputY;
        this.requestCode = builder.requestCode;
        FileUtils.createFile(this.filePath);
    }

    public static class Builder implements Serializable {
        private int maxSize = 9;//最大选择数量
        private boolean mutiSelect = true;//是否单选
        private boolean showCamera = false;//是否显示相机
        private boolean crop = false;//是否剪裁
        private int aspectX = 1;
        private int aspectY = 1;
        private int outputX = 500;
        private int outputY = 500;
        private int requestCode = ImageSelector.IMAGE_REQUEST_CODE;
        private ImageLoader imageLoader;

        // 拍照后存放的图片路径（默认 /temp/picture）
        private String filePath = "/temp/pictures";

        private ArrayList<String> pathList = new ArrayList<String>();

        public Builder(ImageLoader imageLoader) {
            this.imageLoader = imageLoader;
        }

        /**
         * 是否单选
         * @return
         */
        public Builder mutiSelect() {
            this.mutiSelect = true;
            return this;
        }

        /**
         * 是否剪裁
         */
        public Builder crop() {
            this.crop = true;
            return this;
        }

        /**
         * 剪裁尺寸
         * @param aspectX
         * @param aspectY
         * @param outputX
         * @param outputY
         * @return
         */
        public Builder crop(int aspectX, int aspectY, int outputX, int outputY) {
            this.crop = true;
            this.aspectX = aspectX;
            this.aspectY = aspectY;
            this.outputX = outputX;
            this.outputY = outputY;
            return this;
        }

        public Builder requestCode(int requestCode) {
            this.requestCode = requestCode;
            return this;
        }

        /**
         * 存储路径
         * @param filePath
         * @return
         */
        public Builder filePath(String filePath) {
            this.filePath = filePath;
            return this;
        }

        /**
         * 已选择的图片路径
          */
        public Builder pathList(ArrayList<String> pathList) {
            this.pathList = pathList;
            return this;
        }


        /**
         * 单选  （默认为多选）  (单选 为 singleSelect)
         */

        public Builder singleSelect() {
            this.mutiSelect = false;
            return this;
        }

        /**
         * 选择最大数量
         *
         * @param maxSize
         * @return
         */
        public Builder mutiSelectMaxSize(int maxSize) {
            this.maxSize = maxSize;
            return this;
        }

        /**
         * 开启拍照功能 （默认开启）
         */
        public Builder showCamera() {
            this.showCamera = true;
            return this;
        }


        public ImageConfig build() {
            return new ImageConfig(this);
        }
    }

    public boolean isCrop() {
        return crop;
    }

    public int getAspectX() {
        return aspectX;
    }

    public int getAspectY() {
        return aspectY;
    }

    public int getOutputX() {
        return outputX;
    }

    public int getOutputY() {
        return outputY;
    }

    public boolean isMutiSelect() {
        return mutiSelect;
    }

    public int getMaxSize() {
        return maxSize;
    }

    public boolean isShowCamera() {
        return showCamera;
    }

    public ImageLoader getImageLoader() {
        return imageLoader;
    }

    public ArrayList<String> getPathList() {
        return pathList;
    }

    public String getFilePath() {
        return filePath;
    }

    public int getRequestCode() {
        return requestCode;
    }
}
